package com.it.test3;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MyRunnable implements Runnable {
    static int num = 0;
    static Lock lock = new ReentrantLock();
    public void run() {
        while (true) {
            lock.lock();
            try {
                if (num >= 101) {
                    System.out.println("结束");
                    break;
                }
                if(num%2 != 0){
                    System.out.println(Thread.currentThread().getName()+":"+num);
                }
                num++;
            } finally {
                lock.unlock();
            }
        }
    }
}
